package com.atguigu.exam.exception;

import com.atguigu.exam.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    //处理异常的方法
    @ExceptionHandler(value = Exception.class)
    public Result doResolveException(Exception e){
        log.error("系统异常:{}",e.getMessage());
        e.printStackTrace();
        return Result.error(e.getMessage());
    }
    //处理ExamException的方法
    @ExceptionHandler(value = ExamException.class)
    public Result doResolveExamException(ExamException e){
        log.error("业务异常:{}",e.getMessage());
        return Result.error(e.getCode(),e.getMessage());
    }
}
